/*
 * @Author: your name
 * @Date: 2021-02-17 22:08:29
 * @LastEditTime: 2021-02-19 00:04:41
 * @LastEditors: Please set LastEditors
 * @Description: 分页混入
 * @FilePath: \jianfa-admin\src\assets\mixins\pnging.js
 */
export default {
  mounted() {
    //首次加载获取一次数据
    this.getData({
      page: this.page_config.currentPage,
      limit: this.page_config.pageSize,
    });
  },
  data() {
    return {
      //分页配置
      page_config: {
        currentPage: 1,
        total: '',
        layout: "total, sizes, prev, pager, next, jumper",
        background: true,
        pageSize: 5,
        pageSizes: [2, 3 ,4, 5, 10, 15, 20 , 50 , 100],
      },

    }
  },
  computed: {
    //分页查询接口参数
    api_params() {
      let params = {
        page: this.page_config.currentPage,
        limit: this.page_config.pageSize,
      }
      if (this.searchForm) {
         Object.keys(this.searchForm).forEach(key => {
          this.searchForm[key] ? null : delete this.searchForm[key]
         })
        params = {
          ...params,
          ...this.searchForm
        }
      }
      return params
    }
  },
  methods: {
    //切换条数
    sizeChange(val) {
      this.page_config.currentPage = 1;
      this.page_config.pageSize = val;
      this.getData(this.api_params);
    },
    //切换页码
    currentChange(val) {
      this.page_config.currentPage = val;
      this.getData(this.api_params);
    },
  }
}